home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / adynware / control.pm < prev    next >
Encoding:
Perl POD Document  |  1999-12-28  |  20.8 KB  |  497 lines

  1. package control;
  2. use strict;
  3. use diagnostics;
  4. use adynware::web_gen;
  5.  
  6. my %__lists = ();
  7.  
  8. sub displayList
  9. {
  10.         my($infoReference) = @_;
  11.         my($writable, $isMapping, $valueLabel, $shortName, $title, $keyLabel, $textBelowTitle, $hashReference) = @$infoReference;
  12.                                                  
  13.                         
  14.         my $content = "<tr>";
  15.         $content .= "<td>";
  16.         $content .= "<a name=$shortName></a>\n";
  17.         $content .= ButtonLinkToHelp($shortName);
  18.         $content .= CellHeader($title);
  19.         $content .= $textBelowTitle;
  20.                                                                                         
  21.         $content .= "</td>\n";
  22.         $content .= "<td><table>\n";
  23.                                         
  24.         my %hash = %$hashReference;
  25.         my @hashKeys = sort keys %hash;
  26.         my $listEmpty = !scalar(@hashKeys);
  27.         if ($isMapping)
  28.         {
  29.                 $content .= "<script language=\"JavaScript\">var $shortName" . "_values = new Array();\n";
  30.                 for (my $j = 0; $j <  scalar(@hashKeys); $j++)
  31.                 {
  32.                         $content .= $shortName . "_values[$j] = \"$hash{$hashKeys[$j]}\";\n";
  33.                 }
  34.                 $content .= "</script>\n";
  35.         }
  36.                 
  37.                                 
  38.         if ($writable)
  39.         {
  40.                 $content .= "<tr><td>\n";
  41.                 my $handler;
  42.                 if ($isMapping)
  43.                 {
  44.                         $handler = "'AddToMapping(\"$shortName\", \"site\", \"$valueLabel\", mostRecentDocument, \"\")'";
  45.                 }
  46.                 else
  47.                 {
  48.                         $handler = "'AddToSet(\"$shortName\", \"site\", mostRecentDocument)'";
  49.                 }
  50.                 $content .= web_gen::Button("add_$shortName", "Add", "onClick=$handler");
  51.                 if (!$listEmpty)
  52.                 {
  53.                         $content .= "   ";
  54.                         if ($isMapping)
  55.                         {
  56.                                 $content .= web_gen::Button("edit_$shortName", "Edit $valueLabel", "onClick='EditMapping(\"$shortName\", \"$keyLabel\", \"$valueLabel\")'");
  57.                         }
  58.                         else
  59.                         {
  60.                                 $content .= web_gen::Button("edit_$shortName", "Edit $valueLabel", "onClick='Edit(\"$shortName\", \"$keyLabel\", \"$valueLabel\")'");
  61.                         }                
  62.                         $content .= "   ";
  63.                         $content .= web_gen::Button("delete_$shortName", "Delete", "onClick='DeleteFromSet(\"$shortName\")'");
  64.                 }
  65.                 $content .= "</td>";
  66.                 $content .= "</tr>\n";
  67.         }
  68.         $content .= "<tr><td>\n";
  69.         if (!$listEmpty)
  70.         {
  71.                 $content .= web_gen::Select($shortName, "multiple", 4, \@hashKeys, \@hashKeys);
  72.         }
  73.         $content .= "</td></tr>\n";
  74.         $content .= "</table></td>\n";
  75.         $content .= "</tr>\n";
  76.         return $content;
  77. }
  78.  
  79. sub CellHeader
  80. {
  81.         my($header) = @_;
  82.         return "<font size=+2>    $header</font><br>\n";
  83. }
  84.  
  85. sub Header
  86. {
  87.         my($mostRecentDocument, $version) = @_;
  88.                 
  89.         my $header1 = "<head><title>Spinach $version Control</title><script language=\"JavaScript\">var mostRecentDocument = '$mostRecentDocument';";
  90.                 
  91.         my $header2 =<<'EOS';
  92.         var originalIntegerSettings = "";
  93.                 
  94.         function IsWhite(c)
  95.         {
  96.                 return (c==' ') || (c=='\t') || (c=='\n');
  97.         }
  98.                 
  99.         function Trim(s)
  100.         {
  101.                 if (s=="") return "";
  102.                 var start = 0;        
  103.                 while (IsWhite(s.charAt(start))) 
  104.                 {
  105.                         start++;
  106.                         if (start>=s.length) return "";
  107.                 }
  108.                 var end = s.length - 1;        
  109.                 while (IsWhite(s.charAt(end))) 
  110.                 {
  111.                         if (end<=0) return "";
  112.                         end--;
  113.                 }
  114.                 return s.substring(start, end+1);
  115.         }
  116.                 
  117.         function AddToSet(listName, label, defaultItem)
  118.         {
  119.                 var key = PromptForMappingKey(listName, label, defaultItem);
  120.                 if(!key) return;
  121.                 var stuff = "$spinach__" + listName + '{' + key + '} = 1;\n';
  122.                 if (listName == "noCache")
  123.                 {
  124.                         stuff += 'RemovePageAndItsChildren(' + key + ');\n';
  125.                 } 
  126.                 Save(stuff, listName);
  127.         }
  128.                 
  129.                 
  130.         function DeleteFromSet(listName)
  131.         {
  132.                 var item = 0;
  133.                 var field = eval("document.spinach_main." + listName);
  134.                 for (var j = 0; j<field.options.length; j++)
  135.                 {
  136.                         if(field.options[j].selected)
  137.                         {
  138.                                 item = Trim(field.options[j].value);
  139.                                 if(!confirm("remove " + item + " from " + listName + " list?")) return;
  140.                                 var stuff = 'delete($spinach__' + listName + '{"' + item + '"});\n';
  141.                                 if ((listName == "useCache") || (listName == "userSpecifiedPrefetchTargets"))
  142.                                 {
  143.                                         stuff += 'RemovePageAndItsChildren("' + item + '");\n';
  144.                                 } 
  145.                                 Save(stuff, listName);
  146.                         }
  147.                 }
  148.         }
  149.                         
  150.         function PromptForMappingKey(listName, keyLabel, defaultKey)
  151.         {
  152.                 var key = prompt("enter the " + keyLabel + " for the " + listName + " list:", defaultKey);
  153.                 if(!key) return null;
  154.                 return '"' + Trim(key) + '"';
  155.         }
  156.                 
  157.         function PromptForMappingValue(listName, keyLabel, valueLabel, key, defaultValue)
  158.         {
  159.                 var value = prompt("enter the " + valueLabel + " to associate with " + keyLabel + " " + key, defaultValue);
  160.                 if(!value) return null;
  161.                 return '"' + Trim(value) + '"';
  162.         }
  163.                 
  164.         function AddToMapping(listName, keyLabel, valueLabel, defaultKey, defaultValue)
  165.         {
  166.                 var key = PromptForMappingKey(listName, keyLabel, defaultKey);
  167.                 if(!key) return;
  168.                 var value = PromptForMappingValue(listName, keyLabel, valueLabel, key, defaultValue);
  169.                 if(!value) return;
  170.                 Save( "$spinach__" + listName + '{' + key + '} = ' + value + ';\n', listName);
  171.         }
  172.                         
  173.                                 
  174.         function verifyDigits(s)
  175.         {
  176.                 for (var j=0; j<s.length; j++)
  177.                 {
  178.                         var c=s.charAt(j);
  179.                         if (c<'0' || c>'9')
  180.                         {
  181.                                 alert('invalid value: expected digits');
  182.                                 return false;
  183.                         }
  184.                 }
  185.                 return true;
  186.         }
  187.         
  188.         function Edit(listName, keyLabel, valueLabel)
  189.         {
  190.                 var field = eval("document.spinach_main." + listName);
  191.                 for (var j = 0; j<field.options.length; j++)
  192.                 {
  193.                         if(field.options[j].selected)
  194.                         {
  195.                                 var key = field.options[j].value;
  196.                                 var value = PromptForMappingKey(listName, keyLabel, key);
  197.                                 if(!value) return;
  198.                                 Save( "delete($spinach__" + listName + '{"' + key + '"});\n$spinach__' + listName + '{' + value + '} = 1;\n', listName);
  199.                                 return;
  200.                         }
  201.                 }
  202.                 if(!item) return;
  203.         }
  204.                         
  205.         function EditMapping(listName, keyLabel, valueLabel)
  206.         {
  207.                 var field = eval("document.spinach_main." + listName);
  208.                 for (var j = 0; j<field.options.length; j++)
  209.                 {
  210.                         if(field.options[j].selected)
  211.                         {
  212.                                 var key = '"' + field.options[j].value + '"';
  213.                                 var value = PromptForMappingValue(listName, keyLabel, valueLabel, key, eval(listName + "_values[" + j + "]"));
  214.                                 if(!value) return;
  215.                                 Save( "$spinach__" + listName + '{' + key + '} = ' + value + ';\n', listName);
  216.                                 return;
  217.                         }
  218.                 }
  219.                 if(!item) return;
  220.         }
  221.                         
  222.         function Save(stuff, nextAnchor)
  223.         {
  224.                 location = "http://www.adyn.com/spinach/backstop/control.html?" + escape(stuff) + "#" + nextAnchor;
  225.         }
  226.         function utility_getSelected(options)
  227.         {
  228.                 var i;
  229.                 for(i = 0; i < options.length; i++)
  230.                 {
  231.                         if (options[i].checked) break;
  232.                         if (options[i].selected) break;
  233.                 }
  234.                 return options[i].value;
  235.         }
  236.         function CheckBoxChanged(variableName)
  237.         {
  238.                 Save( "$spinach__" + variableName + "=" + eval("document.spinach_main." + variableName + ".checked?1:0") + ";\n", variableName);
  239.         }
  240.         function Shutdown()
  241.         {
  242.                 location = "http://__spinach__/close.html?" + escape( "ShutdownAtNextCheckPoint()" );
  243.         }
  244.         
  245.         function RadioChanged(variableName)
  246.         {
  247.                 Save( "$spinach__" + variableName + "=" + eval("utility_getSelected(document.spinach_main." + variableName + ")") + ";\n", variableName);
  248.         }
  249.         function ChangeInteger(variableName, what, multiplier)
  250.         {
  251.                 ChangeField(variableName, what, multiplier, 1);
  252.         }
  253.         function ChangeField(variableName, what, multiplierOrEmptyAllowed, numeric)
  254.         { 
  255.                 var value = prompt("enter " + what + ":", "");
  256.                 if (numeric)
  257.                 {
  258.                         if (!value) return;
  259.                         var multiplier = multiplierOrEmptyAllowed;
  260.                         if (!verifyDigits(value)) return;
  261.                         value *= multiplier;
  262.                 }
  263.                 else
  264.                 {
  265.                         var emptyAllowed = multiplierOrEmptyAllowed;
  266.                         if (!emptyAllowed && !value) return;
  267.                         value = '"' + value + '"';
  268.                 }
  269.  
  270.                 Save( "$spinach__" + variableName + "=" + value + ";\n", variableName);
  271.         }
  272.         function ClearBrowserCacheCatalog(variableName)
  273.         {
  274.                 if (confirm("tell Spinach that the browser cache has been cleared?"))
  275.                 {
  276.                         Save( "ClearBrowserCacheCatalog();", variableName);
  277.                 }
  278.                 else
  279.                 {
  280.                         document.spinach_main.clearBrowserCacheCatalog.checked = 0;
  281.                 }
  282.         }
  283.                 
  284.         </script>
  285.         </head>
  286. EOS
  287.     return $header1 . $header2;
  288. }
  289.  
  290. sub ButtonLinkToHelp
  291. {
  292.         my($linkName) = @_;
  293.         
  294.         return "<!--link $linkName label-->" . 
  295.         "<input type=button value='Help' name=help_$linkName onclick='window.location=\"http://__spinach__/spinach.html#$linkName\"'>\n";
  296. }
  297.  
  298. sub DataField
  299. {
  300.         my($name, $label, $multiplierOrEmptyAllowed, $isNumeric) = @_;
  301.         return "<a name=data_field$label></a>" . web_gen::Button($name, "Change", "onClick='ChangeField(\"$name\", \"$label\", $multiplierOrEmptyAllowed, $isNumeric)'");
  302. }
  303.  
  304. sub generate
  305. {
  306.         my($proxyServer, $proxyPort, $port, $version, $suppressAds, $noPrefetchBeforeFirstBrowserQuery, $prefetchEnabled, $prefetchMaxItems, $imageCaching,
  307.         #$popupControlMode,
  308.         $cacheSizeLimit, $cacheSize, $customerID, $stalenessTime, $mostRecentDocument, $arrayOfListReferences) = @_;
  309.                 
  310.         
  311.         my $content = Header($mostRecentDocument, $version);
  312.         $content .= "<body>";
  313.         $content .= web_gen::FormBegin("spinach_main");
  314.         $content .= "<font size=6><b>Spinach";
  315.         $content .= "ControlPage</b></font>";
  316.                 
  317.         $content .= web_gen::Button("shutdown", "Shutdown", "onClick='Shutdown()'");
  318.                 
  319.         $content .= "<br>This page controls Spinach Browser's behavior";
  320.                 
  321.         $content .= "<table border cellpadding=5>\n";
  322.                                                                                        
  323.         foreach my $list (@$arrayOfListReferences)
  324.         {
  325.                 my($writable, $isMapping, $valueLabel, $shortName, $title, $textBelowTitle, $hashReference) = @$list;
  326.                 $__lists{$shortName} = $list;
  327.         }
  328.                                                                                 
  329.         $content .= "<tr><td>";
  330.         $content .= "<a name=suppressAds></a>\n";
  331.         $content .= ButtonLinkToHelp("suppressAds");
  332.         $content .= CellHeader("Ad Suppression");
  333.         $content .= "</td><td>\n"; 
  334.         $content .= web_gen::CheckBox("suppressAds", 1, $suppressAds, 
  335.         
  336.         "suppress ad banners", # THIS STRING IS QUOTED IN THE DOCUMENTATION!
  337.         
  338.         "onClick='CheckBoxChanged(\"suppressAds\")'");
  339.         $content .= "</td></tr>\n";
  340.                              
  341.                 
  342.         $content .= displayList(delete($__lists{"advertisers"}));
  343.         
  344.                 
  345.                 
  346.                         
  347.                                            
  348.                                 
  349.                                                          
  350.         $content .= "<tr><td>";
  351.         $content .= "<a name=prefetchEnabled></a>\n";
  352.         $content .= ButtonLinkToHelp("prefetchEnabled");
  353.         $content .= CellHeader("Prefetching");
  354.         $content .= "direct Spinach to prefetch web pages you frequently access";
  355.         $content .= "</td><td>\n"; 
  356.         $content .= web_gen::CheckBox("prefetchEnabled", 1, $prefetchEnabled, "prefetching enabled", "onClick='CheckBoxChanged(\"prefetchEnabled\")'");
  357.         $content .= "<br>\n";
  358.         $content .= web_gen::CheckBox("noPrefetchBeforeFirstBrowserQuery", 1, $noPrefetchBeforeFirstBrowserQuery, "no prefetching until browser's first HTTP query", "onClick='CheckBoxChanged(\"noPrefetchBeforeFirstBrowserQuery\")'");
  359.         $content .= "<br>\n";
  360.         $content .= DataField("prefetchMaxItems", "maximum pages which will be prefetched at startup", 1, 1);
  361.         $content .= $prefetchMaxItems . " is maximum pages which will be prefetched at startup\n";
  362.         $content .= "</td></tr>\n";
  363.                 
  364.         
  365.                 
  366.         $content .= displayList(delete($__lists{"userSpecifiedPrefetchTargets"}));
  367.         
  368.                 
  369.                                 
  370.         $content .= "<tr><td>";
  371.         $content .= "<a name=imageCaching></a>\n";
  372.         $content .= ButtonLinkToHelp("imageCaching");
  373.         $content .= CellHeader("Supplemental Image Caching");
  374.         $content .= "</td><td>\n";
  375.                                                                                
  376.         $content .= web_gen::CheckBox("imageCaching", 1, $imageCaching, "aggressively use the image cache", "onClick='CheckBoxChanged(\"imageCaching\")'");
  377.         $content .= "<br>";
  378.         $content .= "<a name=clearBrowserCacheCatalog></a>\n";
  379.         $content .= web_gen::Button("clearBrowserCacheCatalog", "Tell Spinach browser cache was cleared", "onClick='ClearBrowserCacheCatalog(\"clearBrowserCacheCatalog\")'");
  380.         $content .= "</td></tr>\n";
  381.                                            
  382.                 
  383.                         
  384.         $content .= displayList(delete($__lists{"noCache"}));
  385.         $content .= displayList(delete($__lists{"useCache"}));
  386.         
  387.         
  388.         
  389.         
  390.         #$content .= "<tr><td>";
  391.         #$content .= "<a name=popupControlMode></a>\n";
  392.         #$content .= ButtonLinkToHelp("popupControlMode");
  393.         #$content .= CellHeader("Popup Mode");
  394.         #$content .= "If a site is on the popup control list, one of the following policies is enforced:</td><td>\n";
  395.                                                                        #
  396.         #$content .= web_gen::Radio("popupControlMode", [0,1,2], ["off: do not interfere", "allow with confirmation", "silently suppress"], $popupControlMode, "onClick='RadioChanged(\"popupControlMode\")'");
  397.         #$content .= "</td></tr>\n";
  398.          #
  399.         #
  400.                         #
  401.         #$content .= displayList(delete($__lists{"popupControl"}));
  402.         
  403.                 
  404.                 
  405.                 
  406.                                         
  407.         $content .= "<tr><td>";
  408.         $content .= ButtonLinkToHelp("cacheSizeLimit");
  409.         $content .= CellHeader("Cache Size Limit");
  410.         $content .= "current cache size is $cacheSize kilobytes";
  411.         $content .= "</td><td>";
  412.                 
  413.         $content .= DataField("cacheSizeLimit", "cache size limit in kilobytes", 1024, 1);
  414.         $content .= int($cacheSizeLimit) . " kilobytes\n";
  415.         $content .= "</td></tr>\n";
  416.                                                                     
  417.         $content .= "<tr><td>";
  418.         $content .= ButtonLinkToHelp("stalenessTime");
  419.         $content .= CellHeader("Cache Item Age Limit");
  420.         $content .= "number of days before items are dropped from the cache";
  421.         $content .= "</td><td>";
  422.         $content .= DataField("stalenessTime", "time limit in days after which cached items are discarded", (24 * 60 * 60), 1);
  423.         $content .= "$stalenessTime\n"; 
  424.         $content .= "days</td></tr>\n";
  425.                         
  426.                         
  427.                         
  428.                 
  429.         $content .= "<tr><td>";
  430.         $content .= ButtonLinkToHelp("auditMode");
  431.         $content .= CellHeader("Audit Mode");
  432.         $content .= "open audit window";
  433.         $content .= "</td><td>\n";
  434.         $content .= web_gen::Button("auditMode", "Audit Mode", "onClick='window.location=\"http://www.adyn.com/spinach/backstop/audit.html\"'");
  435.         $content .= "</td></tr>\n";
  436.                 
  437.                         
  438.  
  439.         $content .= "<tr><td>";
  440.         $content .= ButtonLinkToHelp("customerIDspinach");
  441.         $content .= CellHeader("Customer ID");
  442.         $content .= "</td><td>$customerID\n"; 
  443.         $content .= "</td></tr>\n";
  444.                                                                         
  445.         $content .= "<tr><td>";
  446.         $content .= "<a name=proxyServer></a>\n";
  447.         $content .= ButtonLinkToHelp("proxyServer");
  448.         $content .= CellHeader("Proxy Server");
  449.         $content .= "proxy server to which spinach should forward queries";
  450.         $content .= "</td><td>\n"; 
  451.         $content .= web_gen::Button("proxyServer", "Change", "onClick='ChangeField(\"proxyServer\", \"proxy server\", 1, 0)'");
  452.         if ($proxyServer)
  453.         {
  454.                 $content .= "next chained proxy host is $proxyServer\n<br>"; 
  455.                 $content .= DataField("proxyPort", "proxy port", 1, 1);
  456.                 $content .= "on port $proxyPort\n<br>"; 
  457.                 $content .= "</td></tr>\n";
  458.                                                                                 
  459.                 $content .= "<tr><td>";
  460.                 $content .= displayList($__lists{"noProxy"});
  461.         }
  462.         else
  463.         {
  464.                 $content .= "there is no additional proxy host\n"; 
  465.         }
  466.         delete($__lists{"noProxy"});
  467.         
  468.         $content .= "</td></tr>\n";
  469.                                                                 
  470.         $content .= "<tr><td>";
  471.         $content .= ButtonLinkToHelp("portspinach");
  472.         $content .= CellHeader("Spinach Port");
  473.         $content .= "browsers send queries to this port, which spinach listens to";
  474.         $content .= "</td><td>\n"; 
  475.         $content .= DataField("port", "spinach port", 1, 1);
  476.         $content .= "Port $port\n"; 
  477.         $content .= "</td></tr>\n";
  478.         
  479.                 
  480.                         
  481.         foreach my $listName (keys %__lists)
  482.         {
  483.                 $content .= displayList($__lists{$listName});
  484.         }
  485.                 
  486.                         
  487.         $content .= "</table>\n";
  488.         $content .= "<br><a href='mailto:spinach_bugs@" . "adyn.com?subject=problem with Spinach' alt='mail spinach_bugs@" . "adyn.com'>To report a bug</a>\n";
  489.         $content .= "<br><a href='mailto:spinach_user_feedback@" . "adyn.com' alt='mail spinach_user_feedback@" . "adyn.com'>To send feedback concerning Browser Spinach</a>\n";
  490.         $content .= "<br><a href='mailto:support@" . "adyn.com' alt='mail support@" . "adyn.com'>To contact Adynware Corp.</a>\n";
  491.         $content .= "<br><a href='http://www.adyn.com/spinach/summary.html'>To purchase Browser Spinach</a>\n";
  492.         $content .= web_gen::FormEnd();
  493.         $content .= "</body>\n";
  494.         return $content;
  495. }
  496. 1;
  497.